interface EnumToOptionsConfig<T> {
  valueKey?: string
  labelKey?: string
  labelTransform?: (key: string, value: T) => string
}

export const enumToOptions = <T extends number | string>(
  enumObj: any,
  config: EnumToOptionsConfig<T> = {}
) => {
  const { valueKey = 'value', labelKey = 'label', labelTransform = (key: string) => key } = config
  return Object.keys(enumObj)
    .filter((key) => isNaN(Number(key)))
    .map((key) => ({
      [valueKey]: enumObj[key] as T,
      [labelKey]: labelTransform(key, enumObj[key])
    }))
}
